🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / feature / settings / src / androidMain / kotlin / org / meshtastic / feature / settings / tak / TakPermissionUtil.kt
Displaying Raw • Download
feature/settings/src/androidMain/kotlin/org/meshtastic/feature/settings/tak/TakPermissionUtil.kt bbef7670a13ecb0bbdd88f6a0ca886fc4bdb0e9a (bbef7670) Text, 2.50 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.settings.tak
Tff7b72import T7ee787androidx.compose.runtime.Composable
Tff7b72import T7ee787androidx.compose.runtime.LaunchedEffect
Tff7b72import T7ee787org.meshtastic.core.ui.util.PermissionStatus
Tff7b72import T7ee787org.meshtastic.core.ui.util.rememberLocalNetworkPermissionState
Tf0883e@Composable
Tff7b72actual Tff7b72fun Td2a8ffTakPermissionHandlerTb4b4b4(Te6edf3isTakServerEnabledTb4b4b4: Tffa657BooleanTb4b4b4, Te6edf3onPermissionResultTb4b4b4: Tb4b4b4(Tffa657BooleanTb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
T8b949e// ACCESS_LOCAL_NETWORK runtime permission (Android 17 / API 37+) is required for the TAK Server's
T8b949e// localhost socket binding (127.0.0.1:8087). It is also required globally for NSD/mDNS device discovery
T8b949e// when targetSdk >= 37, and is requested up-front from the Connections screen, so it will usually
T8b949e// already be granted by the time the user enables TAK. This composable handles the standalone case
T8b949e// (e.g. user opens TAK settings before ever tapping the network-scan toggle).
Tff7b72val Te6edf3permission Tff7b72= Te6edf3rememberLocalNetworkPermissionStateTb4b4b4(Tb4b4b4)
T8b949e// The launcher must run as a post-composition side effect — invoking it directly in the composition body crashes
T8b949e// with "Launcher has not been initialized". Keying on the status enum re-runs only on real transitions: request
T8b949e// once when never asked, and disable the server on any denial (preserving the prior request-once-then-disable
T8b949e// behavior, now with PERMANENTLY_DENIED treated the same as a fresh denial).
Te6edf3LaunchedEffectTb4b4b4(Te6edf3isTakServerEnabledTb4b4b4, Te6edf3permissionTb4b4b4.Te6edf3statusTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3isTakServerEnabledTb4b4b4) Tff7b72returnTf0883e@LaunchedEffect
Tff7b72when Tb4b4b4(Te6edf3permissionTb4b4b4.Te6edf3statusTb4b4b4) Tb4b4b4{
Te6edf3PermissionStatusTb4b4b4.Te6edf3GRANTED Tff7b72-Tff7b72> Te6edf3onPermissionResultTb4b4b4(Tff7b72trueTb4b4b4)
Te6edf3PermissionStatusTb4b4b4.Te6edf3NOT_REQUESTED Tff7b72-Tff7b72> Te6edf3permissionTb4b4b4.Te6edf3requestTb4b4b4(Tb4b4b4)
Te6edf3PermissionStatusTb4b4b4.Te6edf3DENIED_CAN_RETRYTb4b4b4,
Te6edf3PermissionStatusTb4b4b4.Te6edf3PERMANENTLY_DENIEDTb4b4b4,
Tff7b72-Tff7b72> Te6edf3onPermissionResultTb4b4b4(Tff7b72falseTb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.27s